package cn.innosmart.aq.chart;

import android.content.Context;
import android.widget.TextView;


import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;

import java.util.ArrayList;

import cn.innosmart.aq.R;

/**
 * Custom implementation of the MarkerView.
 *
 * @author Philipp Jahoda
 */
public class MyMarkerView extends MarkerView {

    private TextView tvContent;
    private ArrayList<String> xValues;

    public MyMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);

        tvContent = (TextView) findViewById(R.id.tvContent);
    }

    // callbacks everytime the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        if (xValues != null)
            tvContent.setText(String.format(getContext().getString(R.string.markview), xValues.get(e.getXIndex()), e.getVal()));
        else
            tvContent.setText("" + e.getVal());
    }

    @Override
    public int getXOffset(float xpos) {
        return 20;
    }

    @Override
    public int getYOffset(float ypos) {
        return -getHeight()-20;
    }

    public void setXValues(ArrayList<String> xValues) {
        if (xValues != null)
            this.xValues = xValues;
    }

//    @Override
//    public int getXOffset() {
//        // this will center the marker-view horizontally
//
//    }
//
//    @Override
//    public int getYOffset() {
//        // this will cause the marker-view to be above the selected value
//
//    }
}
